package Recursion;


public class Problem1 {

    public static void main(String[] args) {
        printfChar1("lisi",0);
    }
    public static void printfChar1(String arr, int n) {
        if (n == arr.length()) {
            return;
        }
        printfChar1(arr,n + 1);
        System.out.println(arr.charAt(n));
    }

    //二分查找
    public static void main3(String[] args) {
        int[] arr = {1,4,7,9,10,14,19};
        int left = 0;
        int right = arr.length - 1;
        int t = binarySearch(left,right,5,arr);
        System.out.println(t);

    }
    public static int  binarySearch(int left ,int right,int target,int[] arr) {
        int mid = (left + right) >>> 1;
        if (left >= right) {
            return -1;
        }
        if (arr[mid] < target) {
            return binarySearch(mid + 1,right,target,arr);

        } else if (target < arr[mid]) {
            return binarySearch(left,mid - 1,target,arr);
        }else {
           return mid;
        }
    }


    //方向打印字符串
    public static void main2(String[] args) {
        String str = "lisi";
        char[] arr = str.toCharArray();
        printfChar(arr,0);
    }
    public static int i = 0;
    public static void printfChar (char[] arr, int i) {
        if (arr.length - 1 == i ) {
            System.out.print(arr[i] + " ");
            return;
        }
        printfChar(arr, i+1);
        System.out.print(arr[i] + " ");
    }


    //用递归实现阶乘
    public static void main1(String[] args) {
        System.out.println(factorial(5));
    }
    public static int factorial (int value) {
        if (value == 1) {
            return  1;
        }
        return value * factorial(value - 1);
    }
}
